package com.songlanyun.modules.account.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.MemberConstant;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.modules.account.dao.UserServiceAreaDao;
import com.songlanyun.modules.account.entity.UserServiceAreaEntity;
import com.songlanyun.modules.account.service.AccountService;
import com.songlanyun.modules.account.service.UserServiceAreaService;
import com.songlanyun.modules.exception.MemberException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import javax.annotation.Resource;


@Service("userServiceAreaService")
public class UserServiceAreaServiceImpl extends ServiceImpl<UserServiceAreaDao, UserServiceAreaEntity> implements UserServiceAreaService {

    @Resource
    private AccountService accountService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserServiceAreaEntity> page = this.page(
                new Query<UserServiceAreaEntity>().getPage(params),
                new QueryWrapper<UserServiceAreaEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public List<UserServiceAreaEntity> loadByUserId(Long userId, boolean tw) {
        List<UserServiceAreaEntity> list = this.lambdaQuery().eq(UserServiceAreaEntity::getUserId, userId).list();
        if (CollectionUtil.isEmpty(list) && tw) {
            throw new RRException(MemberException.MEMBER_SERVICE_AREA_RELATIONSHIP_DOES_NOT_EXIST);
        }
        return list;
    }

}
